﻿using WinRTFramework.Common;
using WinRTFramework.DefaultImplementations;
using WinRTFramework.Interfaces.Contracts.Sharing;

namespace ShareSource.ViewModels
{
    class ShareTextViewModel : DefaultPageViewModel, ISupportSharingSourceContract
    {
        private string _sharingText;
        public string SharingText
        {
            get { return _sharingText; }
            set { _sharingText = value; NotifyPropertyChanged(() => SharingText); }
        }

        private DelegateCommand _shareCommand;
        public DelegateCommand ShareCommand
        {
            get { return _shareCommand = _shareCommand ?? new DelegateCommand(OnShare); }
        }

        private void OnShare()
        {
            SharingService.ShowShareUI();
        }

        #region ISupportSharingSourceContract
        public void OnShareRequested(Windows.ApplicationModel.DataTransfer.DataRequest dataRequest)
        {
            if(string.IsNullOrEmpty(SharingText))
            {
                dataRequest.FailWithDisplayText("No Text provided!");
                return;
            }

            dataRequest.Data.Properties.Title = "Text Sharing Example";
            dataRequest.Data.SetText(SharingText);
        }

        public ISharingService SharingService { get; set; }
        #endregion
    }
}
